import axios from 'axios'
import store from '@/store'
import { getToken } from '@/utils/auth'
import router from '@/router'
import { Message } from 'element-ui';

axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
// create an axios instance
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: 10000 // request timeout
})

export const bb = 'http://121.5.36.223:8160';


// request interceptor
service.interceptors.request.use(
  config => {
    // console.log((Date.parse(new Date()).valueOf()-window.localStorage.getItem('BeginTime')))
    // console.log(Math.floor((Date.parse(new Date()).valueOf()-window.localStorage.getItem('BeginTime'))/(50*20)));
    //console.log(Math.floor((Date.parse(new Date()).valueOf()-window.localStorage.getItem('BeginTime'))/(86400000*29)));
    if(Math.floor((Date.parse(new Date()).valueOf()-window.localStorage.getItem('BeginTime'))/(86400000*29))>1&&
      Math.floor((Date.parse(new Date()).valueOf()-window.localStorage.getItem('BeginTime'))/(86400000*29))<600){
        Message.warning("登录马上要过期了,请您退出重新登录,以免造成您的操作无效")
    }
    if (window.localStorage.getItem('authorization')) {
      config.headers['authorization'] =  window.localStorage.getItem('authorization')
    }
    // if (store.getters.token) {
    //   config.headers['authorizatio'] = getToken()
    // }
    return config
  },
  err => {
    return Promise.reject(err);
  })


//console.log(Math.floor((Date.parse(new Date()).valueOf()-window.localStorage.getItem('BeginTime'))/86400000));

export default service
